﻿<!--
 Peter
 Created by: Peter Development Team
    http://peter.codeplex.com/
 
 GNU General Public License version 2 (GPLv2)
    http://peter.codeplex.com/license
 
 This code is provided on an AS IS basis, with no WARRANTIES,
  CONDITIONS or GUARANTEES of any kind.
-->
<UserControl x:Class="Peter.View.ViewEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:icons="clr-namespace:Peter.Common.Icons;assembly=Peter.Common"
             xmlns:logic="clr-namespace:Peter.Logic"
             xmlns:controls="clr-namespace:Peter.Common.Controls;assembly=Peter.Common"
             xmlns:autoComplete="clr-namespace:Peter.Common.AutoComplete;assembly=Peter.Common"
             xmlns:common="clr-namespace:Peter.Common;assembly=Peter.Common"
             mc:Ignorable="d"
             d:DesignHeight="500"
             d:DesignWidth="800"
             d:DataContext="{d:DesignInstance logic:ModelEditor}">
   <UserControl.Resources>
      <ResourceDictionary>
         <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/Peter.Common;component/Themes/Common.xaml" />
         </ResourceDictionary.MergedDictionaries>
         <BooleanToVisibilityConverter x:Key="BoolToVisi" />
      </ResourceDictionary>
   </UserControl.Resources>
   <Grid FocusManager.FocusedElement="{Binding ElementName=EditorContentControl}">
      <Grid.RowDefinitions>
         <RowDefinition Height="Auto" />
         <RowDefinition Height="*" />
         <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <Grid.ColumnDefinitions>
         <ColumnDefinition Width="Auto" />
         <ColumnDefinition Width="*" />
         <ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>

      <ContentPresenter Grid.Column="0"
                        Grid.Row="0"
                        Grid.ColumnSpan="3"
                        Content="{Binding Path=TopContent}" />

      <ContentPresenter Grid.Column="2"
                        Grid.Row="1"
                        Content="{Binding Path=RightContent}" />

      <ContentPresenter Grid.Column="0"
                        Grid.Row="2"
                        Grid.ColumnSpan="3"
                        Content="{Binding Path=BottomContent}" />

      <!-- GOTO LINE AND FIND BAR -->
      <Grid Grid.Row="1"
            Grid.Column="0"
            Margin="0,0,5,0"
            Background="{DynamicResource BackgroundBrush}"
            Visibility="{Binding Path=IsFindBarVisible, Converter={StaticResource BoolToVisi}}">
         <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
         </Grid.RowDefinitions>
         <controls:Pane IsExpanded="{Binding Path=IsFindBarVisible, Mode=TwoWay}"
                        Header="Find/Replace"
                        CanCollapse="True">
            <controls:PaneItem>
               <Grid>
                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="*" />
                     <ColumnDefinition Width="*" />
                  </Grid.ColumnDefinitions>
                  <ToggleButton Grid.Column="0"
                                Margin="2,0"
                                IsChecked="{Binding Path=IsFindMode}">
                     <StackPanel Orientation="Horizontal">
                        <icons:IconDisplay Icon="Search" />
                        <TextBlock Text="Find"
                                   Margin="4,0,0,0" />
                     </StackPanel>
                  </ToggleButton>
                  <ToggleButton Grid.Column="1"
                                Margin="2,0"
                                IsChecked="{Binding Path=IsReplaceMode}">
                     <StackPanel Orientation="Horizontal">
                        <icons:IconDisplay Icon="Refreshalt" />
                        <TextBlock Text="Replace"
                                   Margin="4,0,0,0" />
                     </StackPanel>
                  </ToggleButton>
               </Grid>
            </controls:PaneItem>
            <controls:PaneItem>
               <StackPanel Orientation="Vertical">
                  <TextBlock Text="Search for:" />
                  <controls:CommandTextBox x:Name="FindTextBox"
                                           Command="{x:Static common:PeterApplicationCommands.FindNext}"
                                           autoComplete:AutoComplete.DataProvider="{Binding Path=SearchAutoComplete}"
                                           Text="{Binding Path=FindText, UpdateSourceTrigger=PropertyChanged}"
                                           TextWrapping="NoWrap"
                                           VerticalAlignment="Center" />
                  <TextBlock Text="Replace with:"
                             Visibility="{Binding Path=IsReplaceMode, Converter={StaticResource BoolToVisi}}"/>
                  <controls:CommandTextBox x:Name="ReplaceTextBox"
                                           Command="{x:Static common:PeterApplicationCommands.Replace}"
                                           autoComplete:AutoComplete.DataProvider="{Binding Path=SearchAutoComplete}"
                                           Text="{Binding Path=ReplaceText, UpdateSourceTrigger=PropertyChanged}"
                                           Visibility="{Binding Path=IsReplaceMode, Converter={StaticResource BoolToVisi}}"
                                           TextWrapping="NoWrap"
                                           VerticalAlignment="Center" />
                  <TextBlock FontSize="10"
                             VerticalAlignment="Center"
                             HorizontalAlignment="Right"
                             Text="{Binding Path=FindOccurrences}" />
               </StackPanel>
            </controls:PaneItem>
            <controls:PaneItem>
               <Grid>
                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="*" />
                     <ColumnDefinition Width="*" />
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
                     <RowDefinition Height="Auto" />
                     <RowDefinition Height="Auto" />
                  </Grid.RowDefinitions>

                  <Button Grid.Column="0"
                          Grid.Row="0"
                          Margin="0,0,4,0"
                          ToolTip="Find Previous (Shift+F3)"
                          Command="{x:Static common:PeterApplicationCommands.FindPrevious}">
                     <StackPanel Orientation="Horizontal">
                        <icons:IconDisplay Icon="Previous"
                                           FontSize="10"
                                           Margin="2,0" />
                        <TextBlock Text="Previous"
                                   Margin="2,0" />
                     </StackPanel>
                  </Button>

                  <Button Grid.Column="1"
                          Grid.Row="0"
                          ToolTip="Find Next (F3)"
                          Command="{x:Static common:PeterApplicationCommands.FindNext}">
                     <StackPanel Orientation="Horizontal">
                        <icons:IconDisplay Icon="Next"
                                           FontSize="10"
                                           Margin="2,0" />
                        <TextBlock Text="Next"
                                   Margin="2,0" />
                     </StackPanel>
                  </Button>

                  <Button Grid.Column="0"
                          Grid.ColumnSpan="2"
                          Grid.Row="1"
                          Margin="0,4,0,0"
                          ToolTip="Find All"
                          Command="{Binding Path=FindAllCommand}"
                          Visibility="{Binding Path=IsFindMode, Converter={StaticResource BoolToVisi}}">
                     <StackPanel Orientation="Horizontal">
                        <icons:IconDisplay Icon="Searchdocument"
                                           Margin="2,0" />
                        <TextBlock Text="Find All"
                                   Margin="2,0" />
                     </StackPanel>
                  </Button>

                  <Button Grid.Column="0"
                          Grid.ColumnSpan="2"
                          Grid.Row="1"
                          Margin="0,4,0,0"
                          ToolTip="Replace All"
                          Command="{x:Static common:PeterApplicationCommands.ReplaceAll}"
                          Visibility="{Binding Path=IsReplaceMode, Converter={StaticResource BoolToVisi}}">
                     <StackPanel Orientation="Horizontal">
                        <icons:IconDisplay Icon="Searchdocument"
                                           Margin="2,0" />
                        <TextBlock Text="Replace All"
                                   Margin="2,0" />
                     </StackPanel>
                  </Button>
               </Grid>
            </controls:PaneItem>
            <controls:PaneItem>
               <Grid>
                  <Grid.RowDefinitions>
                     <RowDefinition Height="Auto" />
                     <RowDefinition Height="Auto" />
                     <RowDefinition Height="Auto" />
                  </Grid.RowDefinitions>
                  <CheckBox Grid.Row="0"
                            IsChecked="{Binding Path=FindCaseSensitive}"
                            VerticalAlignment="Center"
                            VerticalContentAlignment="Center"
                            Content="Case Sensitive" />
                  <CheckBox Grid.Row="1"
                            Margin="0,5"
                            VerticalAlignment="Center"
                            VerticalContentAlignment="Center"
                            Content="Match entire word" />
                  <CheckBox Grid.Row="2"
                            IsChecked="{Binding Path=IsFindRegex}"
                            VerticalAlignment="Center"
                            VerticalContentAlignment="Center"
                            Content="Regular Expressions" />
               </Grid>
            </controls:PaneItem>
            <controls:PaneItem>
               <StackPanel Orientation="Vertical">
                  <TextBlock Text="{Binding Path=FindStatus}"
                             TextWrapping="Wrap"/>
                  <ScrollViewer HorizontalScrollBarVisibility="Auto"
                                VerticalScrollBarVisibility="Auto">

                  </ScrollViewer>
               </StackPanel>
            </controls:PaneItem>
         </controls:Pane>
         <controls:Pane Grid.Row="1"
                        Margin="0,5,0,0"
                        Header="Go to line #">
            <controls:PaneItem>
               <Grid>
                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="*" />
                     <ColumnDefinition Width="Auto" />
                  </Grid.ColumnDefinitions>
                  <controls:NumericUpDown Precision="0"
                                          Grid.Column="0"
                                          Margin="0,0,5,0"
                                          x:Name="GotoTextBox"
                                          VerticalAlignment="Center"
                                          IsValueUpdateImmediate="True"
                                          VerticalContentAlignment="Center"
                                          PreviewKeyDown="OnGotoLineKeyDown"
                                          Value="{Binding Path=GotoLineNumber}" />
                  <Button Grid.Column="1"
                          Click="OnGotoLineClick">
                     <icons:IconDisplay Icon="CircleArrowRight"
                                        Margin="5,0" />
                  </Button>
               </Grid>
            </controls:PaneItem>
         </controls:Pane>
      </Grid>

      <!-- INSIGHT BAR AND EDITOR-->
      <Grid Grid.Row="1"
            Grid.Column="1">
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
         </Grid.ColumnDefinitions>
         <ContentControl Grid.Column="0"
                         x:Name="EditorContentControl"
                         Content="{Binding Path=Editor}" />
         <controls:InsightBar Grid.Column="1"
                              Margin="0,25,0,25"
                              TotalLines="{Binding Path=Editor.Document.LineCount}"
                              InsightHighlights="{Binding Path=Highlights}"
                              NavigationRequested="OnInsightNavigation"/>
      </Grid>

      <!-- FIND BAR -->
      <!--<Grid Grid.Row="2"
            Grid.Column="0"
            Grid.ColumnSpan="2"
            x:Name="FindBar"
            Margin="0,2,0,0"
            Visibility="{Binding Path=IsFindBarVisible, Converter={StaticResource BoolToVisi}}">

         <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
         </Grid.RowDefinitions>

         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
         </Grid.ColumnDefinitions>

         <Button Grid.Column="0"
                 Grid.Row="0"
                 Click="OnFindReplaceToggle"
                 ToolTip="Toggles between find and replace mode">
            <icons:IconDisplay Icon="Search"
                               FontSize="10"
                               Margin="2,0"
                               x:Name="IconFindReplaceToggle" />
         </Button>

         <controls:CommandTextBox Grid.Column="1"
                                  Grid.Row="0"
                                  Width="200"
                                  FontSize="10"
                                  Margin="4,0"
                                  x:Name="FindTextBox"
                                  Command="{x:Static common:PeterApplicationCommands.FindNext}"
                                  autoComplete:AutoComplete.DataProvider="{Binding Path=SearchAutoComplete}"
                                  Text="{Binding Path=FindText, UpdateSourceTrigger=PropertyChanged}"
                                  PreviewKeyDown="OnSearchKeyDown"
                                  TextWrapping="NoWrap"
                                  VerticalAlignment="Center" />

         <controls:CommandTextBox Grid.Column="1"
                                  Grid.Row="1"
                                  Width="200"
                                  FontSize="10"
                                  Margin="4,0"
                                  x:Name="ReplaceTextBox"
                                  Visibility="Collapsed"
                                  autoComplete:AutoComplete.DataProvider="{Binding Path=SearchAutoComplete}"
                                  Text="{Binding Path=ReplaceText, UpdateSourceTrigger=PropertyChanged}"
                                  PreviewKeyDown="OnSearchKeyDown"
                                  TextWrapping="NoWrap"
                                  VerticalAlignment="Center" />

         <Button Grid.Column="2"
                 Grid.Row="0"
                 Margin="4,0"
                 ToolTip="Find Next (F3)"
                 FontSize="10"
                 Width="75"
                 Command="{x:Static common:PeterApplicationCommands.FindNext}">
            <StackPanel Orientation="Horizontal">
               <icons:IconDisplay Icon="Next"
                                  FontSize="10"
                                  Margin="2,0" />
               <TextBlock Text="Next"
                          Margin="2,0" />
            </StackPanel>
         </Button>

         <Button Grid.Column="3"
                 Grid.Row="0"
                 ToolTip="Find Previous (Shift+F3)"
                 FontSize="10"
                 Width="75"
                 Command="{x:Static common:PeterApplicationCommands.FindPrevious}">
            <StackPanel Orientation="Horizontal">
               <icons:IconDisplay Icon="Previous"
                                  FontSize="10"
                                  Margin="2,0" />
               <TextBlock Text="Previous"
                          Margin="2,0" />
            </StackPanel>
         </Button>

         <Button Grid.Column="2"
                 Grid.Row="1"
                 FontSize="10"
                 Width="75"
                 Visibility="Collapsed"
                 x:Name="_BtnReplaceNext"
                 Command="{x:Static common:PeterApplicationCommands.Replace}">
            <StackPanel Orientation="Horizontal">
               <icons:IconDisplay Icon="Next"
                                  FontSize="10"
                                  Margin="2,0" />
               <TextBlock Text="Replace"
                          Margin="2,0" />
            </StackPanel>
         </Button>

         <Button Grid.Column="3"
                 Grid.Row="1"
                 FontSize="10"
                 Width="75"
                 Visibility="Collapsed"
                 x:Name="_BtnReplaceAll"
                 Command="{x:Static common:PeterApplicationCommands.ReplaceAll}">
            <StackPanel Orientation="Horizontal">
               <icons:IconDisplay Icon="Refreshalt"
                                  FontSize="10"
                                  Margin="2,0" />
               <TextBlock Text="Replace All"
                          Margin="2,0" />
            </StackPanel>
         </Button>

         <CheckBox Grid.Column="4"
                   Margin="4,0"
                   Grid.Row="0"
                   IsChecked="{Binding Path=FindCaseSensitive}"
                   HorizontalAlignment="Center"
                   HorizontalContentAlignment="Center"
                   VerticalAlignment="Center"
                   VerticalContentAlignment="Center"
                   FontSize="10"
                   Content="Case Sensitive" />

         <TextBlock Grid.Column="6"
                    Grid.Row="0"
                    Margin="4,0"
                    VerticalAlignment="Center"
                    FontSize="10"
                    Text="{Binding Path=FindOccurrences}" />

         <Button Grid.Column="7"
                 Grid.Row="0"
                 ToolTip="Hide Search"
                 Click="OnHideSearch">
            <icons:IconDisplay Icon="ChevronDown"
                               FontSize="10"
                               Margin="2,0" />
         </Button>
      </Grid>-->
   </Grid>
</UserControl>